package enums;

/**
 * 策略枚举，提供抽象方法实现不同枚举类型
 */
public enum PayType {
    /**
     * 工作日
     */
    WEEKDAY {
        @Override
        double overtimePay(double hours, double payRate) {
            return hours <= HOURS_PER_SHIFT ? 0 : (hours - HOURS_PER_SHIFT)
                    * payRate / 2;
        }
    },
    /**
     * 非周末工作日
     */
    WEEKEND {
        @Override
        double overtimePay(double hours, double payRate) {
            return hours * payRate / 2;
        }
    };
    private static final int HOURS_PER_SHIFT = 8;

    abstract double overtimePay(double hrs, double payRate);

    double pay(double hoursWorked, double payRate) {
        double basePay = hoursWorked * payRate;
        return basePay + overtimePay(hoursWorked, payRate);
    }
}